<template>
  <div class="login">
    <el-form
      :model="ruleForm"
      status-icon
      :rules="rules"
      ref="ruleForm"
      label-width="100px"
      class="login-form"
      label-position="top"
    >
      <el-form-item label="手机号" prop="phone">
        <el-input v-model="ruleForm.phone" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item label="密码" prop="password">
        <el-input
          type="password"
          v-model="ruleForm.password"
          autocomplete="off"
        ></el-input>
      </el-form-item>
      <el-form-item>
        <el-button class="login-btn" type="primary" @click="submitForm('ruleForm')"
          >提交</el-button
        >
      </el-form-item>
    </el-form>
  </div>
</template>

<script lang="ts">
import Vue from 'vue'
import request from '../../utils/request'
import qs from 'qs'
export default Vue.extend({
  data () {
    // var checkPhone = (rule, value, callback) => {
    //   if (!value) {
    //     return callback(new Error('年龄不能为空'))
    //   }
    //   setTimeout(() => {
    //     if (!Number.isInteger(value)) {
    //       callback(new Error('请输入数字值'))
    //     } else {
    //       if (value < 18) {
    //         callback(new Error('必须年满18岁'))
    //       } else {
    //         callback()
    //       }
    //     }
    //   }, 1000)
    // }
    // var validatePass = (rule, value, callback) => {
    //   if (value === '') {
    //     callback(new Error('请输入密码'))
    //   } else {
    //     if (this.ruleForm.checkPass !== '') {
    //       this.$refs.ruleForm.validateField('checkPass')
    //     }
    //     callback()
    //   }
    // }
    return {
      ruleForm: {
        phone: '18201288771',
        password: '111111'
      }
      // rules: {
      //   phone: [
      //     { validator: checkPhone, trigger: 'blur' }
      //   ],
      //   pass: [
      //     { validator: validatePass, trigger: 'blur' }
      //   ]
      // }
    }
  },
  methods: {
    async submitForm (formName: string): void {
      console.log(formName)
      const { data } = await request({
        method: 'post',
        url: '/front/user/login',
        headers: { 'content-type': 'application/x-www-form-urlencoded' },
        data: qs.stringify(this.ruleForm) // axios 默认发送的是application/json 格式的数据
      })
      console.log(data)
    }
  }
})
</script>

<style lang="sass" scoped>
.login
  height: 100vh
  display: flex
  align-items: center
  justify-content: center
  background: #f5f5f5
  &-form
    background: #fff
    width: 360px
    padding: 30px
    border-radius: 5px
  &-btn
    width: 100%

</style>
